import Vue from 'vue'
import VueRouter from 'vue-router'


// 防止重复触发同一个路由
const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}


Vue.use(VueRouter)

const routes = [{
        path: '/login',
        component: () =>
            import ('@/views/login/Login.vue'),
        name: 'login'
    },
    {
        path: '/',
        component: () =>
            import ('@/views/home/Home.vue'),
        name: 'home',
        children: [{
                path: '/',
                component: () =>
                    import ('@/views/index/Index.vue'),
                name: 'index'
            }, {
                path: '/calculate',
                component: () =>
                    import ('@/views/calculate/Calculate.vue'),
                name: 'calculate',
            },
            {
                path: '/calculateDetail',
                component: () =>
                    import ('@/views/calculateDetail/CalculateDetail.vue'),
                name: 'calculateDetail'
            },
            {
                path: '/subjectList',
                component: () =>
                    import ('@/views/subject/SubjectList.vue'),
                name: 'subjectList',
            },
            {
                path: '/subject',
                component: () =>
                    import ('@/views/subject/SubjectHome.vue'),
                // redirect: '/subject',
                name: 'subjectHome',
                children: [{
                        path: '/subject',
                        component: () =>
                            import ('@/views/subject/subject/Subject.vue'),
                        name: 'subject'
                    }, {
                        path: '/solution',
                        component: () =>
                            import ('@/views/subject/solution/Solution.vue'),
                        name: 'solution'
                    },
                    {
                        path: '/result',

                        component: () =>
                            import ('@/views/subject/result/Result.vue'),
                        name: 'result',

                    }
                ]
            },
            {
                path: '/discussList',
                component: () =>
                    import ('@/views/discuss/DiscussList.vue'),
                name: 'discussList',
            },
            {
                path: '/discuss',
                component: () =>
                    import ('@/views/discuss/Discuss.vue'),
                name: 'discuss',
                hidden: true
            },
            {
                path: '/myInfo',
                redirect: '/personal',
                component: () =>
                    import ('@/views/userInfo/UserInfo.vue'),
                // redirect: '/myInfo/personal', //这个是转发（当进入‘/myInfo’路径时自动跳转到/personal路径）
                name: 'userInfo',
                children: [{ // 因为下面几个模块在/myInfo里面所以加这个children
                    path: '/personal',
                    component: () =>
                        import ('@/views/userInfo/personal/Personal.vue'),
                    name: 'personal'
                }, {
                    path: '/collect',
                    component: () =>
                        import ('@/views/userInfo/collect/Collect.vue'),
                    redirect: '/question', //这个是转发（当进入‘/myInfo’路径时自动跳转到/personal路径）

                    name: 'collect',
                    children: [{
                        path: '/collect/question',
                        component: () =>
                            import ('@/views/userInfo/question/Question.vue'),
                        name: 'question'
                    }, {
                        path: '/collect/talk',
                        component: () =>
                            import ('@/views/userInfo/talk/Talk.vue'),
                        name: 'talk',
                        // hidden: true  这个是隐藏页面的意思，比如详情页面是跳出来就可以使用这个
                    }]
                }]
            }
        ]

    }

]

const router = new VueRouter({
    routes
})

export default router